package day05;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/14
 */
public class StringReverse {
    public static void main(String[] args) {
        String str = "Hello World";
        String reverseStr = reverseString(str);
        System.out.println("原始字符串: " + str);
        System.out.println("反转后字符串: " + reverseStr);
    }

    public static String reverseString(String str) {
        char[] charArr = str.toCharArray();
        int left = 0;
        int right = charArr.length - 1;

        while (left < right) {
            // 交换左右字符
            char temp = charArr[left];
            charArr[left] = charArr[right];
            charArr[right] = temp;

            left++;
            right--;
        }

        return new String(charArr);
    }
}
